package cn.hl.sfzy.controller;

import cn.hl.sfzy.entity.FM;
import cn.hl.sfzy.service.FMService;
import cn.hl.sfzy.util.Result;
import com.google.protobuf.Internal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName FMController
 * @Description TODO
 * @Author yangshen
 * @Date 2024年10月24日 11:27
 * @Version 1.0
 */
@RestController
@RequestMapping("/FM")
public class FMController {
    @Autowired
    private FMService service;
    @GetMapping("/find")
    public Result find(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize,
             FM fm){
        return Result.success(service.find(pageNum,pageSize,fm));
    }
    @PostMapping
    public Result add(@RequestBody FM fm){

        if (service.add(fm)!=0){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") long id){
        if (service.delete(id)!=0){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
    @PutMapping
    public Result update(@RequestBody FM fm){

        if (service.update(fm)!=0){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }
}
